<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Binds a parameter to a statement variable</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.sqlite3stmt.html">« SQLite3Stmt</a></li>
      <li style="float: right;"><a href="sqlite3stmt.bindvalue.html">SQLite3Stmt::bindValue »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.sqlite3stmt.html">SQLite3Stmt</a></li>
    <li>Binds a parameter to a statement variable</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="sqlite3stmt.bindparam" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3Stmt::bindParam</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3Stmt::bindParam</span> &mdash; <span class="dc-title">Binds a parameter to a statement variable</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3stmt.bindparam-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3Stmt::bindParam</strong></span>(<span class="methodparam"><span class="type"><span class="type">string</span>|<span class="type">int</span></span> <code class="parameter">$param</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$var</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = <strong><code>SQLITE3_TEXT</code></strong></span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Binds a parameter to a statement variable.
  </p>
  <div class="caution"><strong class="caution">警告</strong>
   <p class="para">
    Before PHP 7.2.14 and 7.3.0, respectively,
    <span class="methodname"><a href="sqlite3stmt.reset.html" class="methodname">SQLite3Stmt::reset()</a></span> must be called after the first call to
    <span class="methodname"><a href="sqlite3stmt.execute.html" class="methodname">SQLite3Stmt::execute()</a></span> if the bound value should be properly
    updated on following calls to <span class="methodname"><a href="sqlite3stmt.execute.html" class="methodname">SQLite3Stmt::execute()</a></span>.
    If <span class="methodname"><a href="sqlite3stmt.reset.html" class="methodname">SQLite3Stmt::reset()</a></span> is not called, the bound value will
    not change, even if the value assigned to the variable passed to
    <span class="methodname"><strong>SQLite3Stmt::bindParam()</strong></span> has changed, or
    <span class="methodname"><strong>SQLite3Stmt::bindParam()</strong></span> has been called again.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3stmt.bindparam-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">param</code></dt>

     <dd>

      <p class="para">
       Either a <span class="type">string</span> (for named parameters) or an <span class="type">int</span>
       (for positional parameters) identifying the statement variable to which the
       value should be bound.
       If a named parameter does not start with a colon (<code class="literal">:</code>) or an
       at sign (<code class="literal">@</code>), a colon (<code class="literal">:</code>) is automatically preprended.
       Positional parameters start with <code class="literal">1</code>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">var</code></dt>

     <dd>

      <p class="para">
       The parameter to bind to a statement variable.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">type</code></dt>

     <dd>

      <p class="para">
       The data type of the parameter to bind.
       <ul class="itemizedlist">
        <li class="listitem">
         <p class="para">
          <strong><code>SQLITE3_INTEGER</code></strong>: The value is a signed integer,
          stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of
          the value.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLITE3_FLOAT</code></strong>: The value is a floating point
          value, stored as an 8-byte IEEE floating point number.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLITE3_TEXT</code></strong>: The value is a text string, stored
          using the database encoding (UTF-8, UTF-16BE or UTF-16-LE).
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLITE3_BLOB</code></strong>: The value is a blob of data, stored
          exactly as it was input.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLITE3_NULL</code></strong>: The value is a NULL value.
         </p>
        </li>
       </ul>
      </p>
      <p class="para">
       As of PHP 7.0.7, if <code class="parameter">type</code> is omitted, it is automatically
       detected from the type of the <code class="parameter">var</code>: <span class="type">bool</span>
       and <span class="type">int</span> are treated as <strong><code>SQLITE3_INTEGER</code></strong>,
       <span class="type">float</span> as <strong><code>SQLITE3_FLOAT</code></strong>, <span class="type">null</span>
       as <strong><code>SQLITE3_NULL</code></strong> and all others as <strong><code>SQLITE3_TEXT</code></strong>.
       Formerly, if <code class="parameter">type</code> has been omitted, it has defaulted
       to <strong><code>SQLITE3_TEXT</code></strong>.
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        If <code class="parameter">var</code> is <strong><code>null</code></strong>, it is always treated as
        <strong><code>SQLITE3_NULL</code></strong>, regardless of the given
        <code class="parameter">type</code>.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-sqlite3stmt.bindparam-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>true</code></strong> if the parameter is bound to the statement variable, <strong><code>false</code></strong>
   on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-sqlite3stmt.bindparam-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.4.0</td>
      <td>
       <code class="parameter">param</code> now also supports the <code class="literal">@param</code>
       notation.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3stmt.bindparam-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1956">
    <p><strong>示例 #1 <span class="function"><strong>SQLite3Stmt::bindParam()</strong></span> Usage</strong></p>
    <div class="example-contents"><p>
     This example shows how a single prepared statement with a single parameter
     binding can be used to insert multiple rows with different values.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$db&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;foo&nbsp;(bar&nbsp;TEXT)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;foo&nbsp;VALUES&nbsp;(:bar)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindParam</span><span style="color: #007700">(</span><span style="color: #DD0000">':bar'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bar</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLITE3_TEXT</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'baz'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">42</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;foo"</span><span style="color: #007700">);<br />while&nbsp;((</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchArray</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLITE3_ASSOC</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$row</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(1) {
  [&quot;bar&quot;]=&gt;
  string(3) &quot;baz&quot;
}
array(1) {
  [&quot;bar&quot;]=&gt;
  string(2) &quot;42&quot;
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-sqlite3stmt.bindparam-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="sqlite3stmt.bindvalue.html" class="methodname" rel="rdfs-seeAlso">SQLite3Stmt::bindValue()</a> - Binds the value of a parameter to a statement variable</span></li>
   <li class="member"><span class="methodname"><a href="sqlite3.prepare.html" class="methodname" rel="rdfs-seeAlso">SQLite3::prepare()</a> - Prepares an SQL statement for execution</span></li>
  </ul>
 </div>


</div></div></div></body></html>